package com.example.sjly.ui.home;

import android.media.Image;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.SearchView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;
import com.example.sjly.R;

public class HomeFragment extends Fragment{

    public ImageButton head_button;
    private ImageView imageView1;
    public ViewPager2 viewPager2;
    private SlidingSwitcherView slidingSwitcherView;
//    public androidx.gridlayout.widget.GridLayout gridLayout;

//    public void onViewCreate(View view,Bundle savedInsatanceState)
//    {
//        ImageButton imageButton3 =gridLayout.findViewById(R.id.imageButton3);
//        ImageButton imageButton4 =gridLayout.findViewById(R.id.imageButton4);
//        ImageButton imageButton5 =gridLayout.findViewById(R.id.imageButton5);
//        ImageButton imageButton6 =gridLayout.findViewById(R.id.imageButton6);
//        ImageButton imageButton7 =gridLayout.findViewById(R.id.imageButton7);
//        ImageButton imageButton8 =gridLayout.findViewById(R.id.imageButton8);
//        ImageButton imageButton9 =gridLayout.findViewById(R.id.imageButton9);
//        ImageButton imageButton10 =gridLayout.findViewById(R.id.imageButton10);
//        ImageButton imageButton11 =gridLayout.findViewById(R.id.imageButton11);
//        ImageButton imageButton12 =gridLayout.findViewById(R.id.imageButton12);
//        ImageButton imageButton13 =gridLayout.findViewById(R.id.imageButton13);
//        ImageButton imageButton14 =gridLayout.findViewById(R.id.imageButton14);
//        ImageButton imageButton15 =gridLayout.findViewById(R.id.imageButton15);
//        ImageButton imageButton16 =gridLayout.findViewById(R.id.imageButton16);
//        imageButton3.setOnClickListener(this);
//        imageButton4.setOnClickListener(this);
//        imageButton5.setOnClickListener(this);
//        imageButton6.setOnClickListener(this);
//        imageButton7.setOnClickListener(this);
//        imageButton8.setOnClickListener(this);
//        imageButton9.setOnClickListener(this);
//        imageButton10.setOnClickListener(this);
//        imageButton11.setOnClickListener(this);
//        imageButton12.setOnClickListener(this);
//        imageButton13.setOnClickListener(this);
//        imageButton14.setOnClickListener(this);
//        imageButton15.setOnClickListener(this);
//        imageButton16.setOnClickListener(this);
//    }

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_home, container, false);
        head_button=root.findViewById(R.id.imageButton);
        head_button.setImageResource(R.drawable.pig);
        slidingSwitcherView=root.findViewById(R.id.slidingLayout);
        slidingSwitcherView.startAutoPlay();
//        gridLayout=getActivity().findViewById(R.id.GridLayout);
//        //8行2列
//        gridLayout.setColumnCount(2);
//        gridLayout.setRowCount(8);
        return root;
    }



    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);

        head_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                viewPager2= getActivity().findViewById(R.id.viewpager);
                viewPager2.setCurrentItem(3);
            }
        });

        }
//     @Override
//    public void onClick(View v){
//        switch (v.getId()){
//            case R.id.imageButton3:
//                Toast.makeText(getActivity(),"网络开小差了...",Toast.LENGTH_LONG).show();
//            case R.id.imageButton4:
//                Toast.makeText(getContext(),"网络开小差了...",Toast.LENGTH_LONG).show();
//            case R.id.imageButton5:
//                Toast.makeText(getContext(),"网络开小差了...",Toast.LENGTH_LONG).show();
//            case R.id.imageButton6:
//                Toast.makeText(getContext(),"网络开小差了...",Toast.LENGTH_LONG).show();
//            case R.id.imageButton7:
//                Toast.makeText(getContext(),"网络开小差了...",Toast.LENGTH_LONG).show();
//            case R.id.imageButton8:
//                Toast.makeText(getContext(),"网络开小差了...",Toast.LENGTH_LONG).show();
//            case R.id.imageButton9:
//                Toast.makeText(getContext(),"网络开小差了...",Toast.LENGTH_LONG).show();
//            case R.id.imageButton10:
//                Toast.makeText(getContext(),"网络开小差了...",Toast.LENGTH_LONG).show();
//            case R.id.imageButton11:
//                Toast.makeText(getContext(),"网络开小差了...",Toast.LENGTH_LONG).show();
//            case R.id.imageButton12:
//                Toast.makeText(getContext(),"网络开小差了...",Toast.LENGTH_LONG).show();
//            case R.id.imageButton13:
//                Toast.makeText(getContext(),"网络开小差了...",Toast.LENGTH_LONG).show();
//            case R.id.imageButton14:
//                Toast.makeText(getContext(),"网络开小差了...",Toast.LENGTH_LONG).show();
//            case R.id.imageButton15:
//                Toast.makeText(getContext(),"网络开小差了...",Toast.LENGTH_LONG).show();
//            case R.id.imageButton16:
//                Toast.makeText(getContext(),"网络开小差了...",Toast.LENGTH_LONG).show();
//
//        }
//        }

//    public boolean onCreateOptionsMenu(Menu menu) {
//        // Inflate the options menu from XML
//        MenuInflater inflater =getActivity().getMenuInflater();
//        inflater.inflate(R.menu.options_menu, menu);
//
//        // Get the SearchView and set the searchable configuration
//        SearchManager searchManager = (SearchManager)getActivity().getSystemService(Context.SEARCH_SERVICE);
//        SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
//        // Assumes current activity is the searchable activity
//        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
//        searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
//
//        return true;
//    }


    }